<template name="component-name">
  <div class="eventLevel">
    <CommonBtn label-name="人员信息管理" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()') " :buttons="buttons" @onButtonClick="onButtonClick">
    </CommonBtn>
    <CommonList ref="list" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect" :conditions="conditions" @dbClick="openItem"></CommonList>
  </div>
</template>
<script>
  import CommonBtn from "../../common/CommonBtn";
  import CommonList from "../../common/CommonList"
  export default {
    name:'ServiceAttributeSetting',
    components:{
      CommonBtn,
      CommonList,
    },
    data(){
      return{
        buttons:[
          this.$config.BTNS.ADD,
          this.$config.BTNS.EDIT,
          this.$config.BTNS.DETAIL,
          this.$config.BTNS.EXPORT,
          this.$config.BTNS.INPORTWORDAY,
          this.$config.BTNS.INPORTOUT,
          this.$config.BTNS.INPORTJJEDS,
          this.$config.BTNS.SEARCH,
        ],
        button:null,
        columns:[
          {
            prop:'accountNumber',
            label:'序号',
          },
          {
            prop:'wwid',
            label:'架构代码',
          },
          {
            prop:'repNameCn',
            label:'架构名称',
          },
          {
            prop:'repType',
            label:'方案名称',
          },
          {
            prop:'repNameCn',
            label:'最后修改人',
          },
          {
            prop:'repNameCn',
            label:'最后修改时间',
          },
          {
            prop:'operate',
            label:'操作',
            minWidth: 120,
            operates:[{
              title: '审批通过',
              action: (item) => {
                this.approvalPass(item)
              }
            }]
          },
        ],
        listUrl:this.$api.API_ORGDRAFT_LIST,
        row: {},
        conditions: [],
      }
    },
    created(){
      this.initData()
    },
    methods:{
      onButtonClick(item) {
          if (item.event == 'edit()' || item.event == 'Delete()' || item.event == 'disable()' || item.event == 'enable()' || item.event == 'detail()') {
              if (!this.row || JSON.stringify(this.row) == '{}') {
                  this.$message.error("请选择一行数据")
                  return
              }
          }
          if (item.event == 'add()') {
              this.tagType = this.add
              this.row = {}
          } else if (item.event == 'edit()') {
            if (this.row.repTypeCode == 1 || this.row.repTypeCode == 2) {
              this.tagType = this.edit
            } else if (this.row.repTypeCode == 3) {
              this.tagType = this.edit1
            }
          } else if (item.event == 'detail()') {
            this.tagType = this.detail
          } else if (item.event == 'inport()') {

            if (item.name == "Workday人员导入") {
              this.templateUrl = "/static/template/门店导入模板.xls"
              this.inportUrlAPI = this.$api.API_MDM_ORG_IMPORTJNJORG
            } else if (item.name == "外部人员导入") {
              this.templateUrl = "/static/template/门店导入模板.xls"
              this.inportUrlAPI = this.$api.API_MDM_ORG_IMPORTEXTERNAL
            } else if (item.name == 'JJEDS人员导入') {
              this.templateUrl = "/static/template/门店导入模板.xls"
              this.inportUrlAPI = this.$api.API_MDM_ORG_IMPORTTHREEORG
            }
          } else if(item.event === 'search()') {
              let self = this
              console.log(this.searchItems)
              this.searchs.push({
              label: '查询人员信息',
              page: 'store',
              searchData: this.searchData,
              items: this.searchItems,
              selectItem: function (formData, items) {
                console.log(items)
                self.searchs.pop()
                self.searchItems = items;
                self.searchData = formData;
                let conditions = self.conditions.filter(item=>{
                  return !item.label
                })
                // 回调
                for (let idx in items) {
                  let item = items[idx]
                  if (item.checked == true) {
                    conditions.push({
                      checked: true,
                      label: item.name,
                      prop: item.vkey ? item.vkey : item.key,
                      valueName: formData[item.key],
                      value: item.vkey ? formData[item.vkey] : formData[item.key]
                    })
                  }
                }
                self.conditions = conditions
              },
            })
          }
          this.button = item
      },
      initData() {},
      openItem(item) {
          this.button = this.$config.BTNS.DETAIL
      },
      close(item) {
        this.button = item
      },
      tableSelect(row) {
        this.row = row
      },
    }
  }
</script>